<?php

namespace app\api\validate;

use think\Validate;

class ProductValidate extends BaseValidate
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'count' => 'require|isPositiveInteger',
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */
    protected $message = [
        'count' => '数量必须为1-15的正整数'
    ];

    public function __construct($method)
    {
        switch ($method)
        {
            case 'getNewList':
                $this->rule = [
                    'count' => 'between:1,15|isPositiveInteger',
                ];
                break;
            case 'getAllByCategory':
                $this->rule = [
                    'categoryId' => 'isPositiveInteger',
                ];
                $this->message = [
                    'categoryId' => '分类ID必须为正整数',
                ];
                break;
            case 'detail':
                $this->rule = [
                    'productId' => 'require|isPositiveInteger',
                ];
                $this->message = [
                    'productId' => '产品ID必须为正整数',
                ];
                break;
        }
    }
}